<template>
  <div :id="id" :class="className" :style="{height:height,width:width}" />
</template>

<script>
import echarts from 'echarts'
import resize from '../../../assets/js/charts/resize'
export default {
  mixins: [resize],
  props: {
    option: {},
    className: {
      type: String,
      default: 'chart'
    },
    id: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '200px'
    },
    height: {
      type: String,
      default: '200px'
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.initChart()
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(document.getElementById(this.id))
      this.chart.setOption({
        color: ["#3A73EB"],
        grid: {//设置左、右、底的间距
          left: 10,
          right: 10,
          bottom: 40
        },
        xAxis: {
          data: this.option.xAxisData,
          axisLine: {
            lineStyle: {
              color: "transparent"
            }
          },
          axisLabel: {
            color: "#fff",
            fontSize: 14
          }
        },
        yAxis: [
          {
            type: "value",
            show: false
          }
        ],
        series: [
          {
            type: "bar",
            barWidth: 24,//设置柱子宽度
            itemStyle: {
              normal: {
                label: {
                  show: true,
                  position: "top",
                  formatter: "{c}" + "次",
                  color: "#fff"
                }
                // shadowBlur: 100,
                // shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            },
            data: this.option.yAxisData
          }
        ]
      })
    }
  }
}
</script>
